<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.firstsoft.firstframe.admin.PropertyFile"%>
<%@ page import="cn.firstsoft.firstframe.admin.XmlFile"%>
<%@ page import="cn.firstsoft.firstframe.admin.Field"%>
<%@ page import="cn.firstsoft.firstframe.admin.MailTest"%>
<%@ page import="org.springside.core.Constants,org.springside.modules.security.service.logic.DeptManager" %>
<%@ page import="java.util.*,org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.web.context.support.*,org.springframework.context.*"%>
<%@page import="com.kingdee.seil.util.Base64"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../common.jsp"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>${typeCname}设置</title>
   	<%@ include file="/common/meta2.jsp"%>
	<link href="../style.css" type="text/css" rel=stylesheet>
	<script language="javascript" src="../Check.js"></script>
  </head>
  <body>
 <% 

 	ApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    DeptManager deptManager = (DeptManager) wac.getBean("deptManager");
    int dept_maxlevel = deptManager.getDeptMaxLevel();
    
 	String typeName = request.getParameter("type")==null?"":request.getParameter("type"); 	
 	List list = XmlFile.findFields(typeName);
 	Map valueMap = new HashMap();
 	String typeCname = "";
 	if(list.size()>0)
 	{
	 	
	 	typeCname = ((Field)list.get(0)).getTypeCname();
	 	
	 	for(int i=0;i<list.size();i++)
	 	{
	 		Field field = (Field)list.get(i);
	 		String value = PropertyFile.readValue("firstframe.properties",field.getPname())==null?"":PropertyFile.readValue("firstframe.properties",field.getPname());		 		
	 		valueMap.put(field.getPname(),value);
	 	}
 	}else
 	{ 	
		out.println("没有找到相关设置，请加入该类型的设置！");	
 		return;

	}
 %>
 

<c:set var="typeName" value="<%=typeName%>"/>
<c:set var="typeCname" value="<%=typeCname%>"/>
<FORM name="workflowForm" action="setting_update.jsp?type=<%=typeName%>" method="post" onsubmit="return CheckForm(this)">
<input class=button type=submit value="提&nbsp;&nbsp;交" />
<input class=button type=reset value="重&nbsp;&nbsp;置" />
<c:set var="flag" value="${param.flag}" />
<c:if test="${not empty flag}">
	<p/>
	<c:if test="${flag == 'suc'}">设置保存成功,并请重新启动服务器！</c:if>
	<c:if test="${flag == 'err'}">
		设置保存失败！
		<c:if test="${param.errMsg != null && param.errMsg != ''}">
		<br><%=new String(Base64.decode(request.getParameter("errMsg")))%>
		</c:if>
	</c:if>
</c:if>
<c:set var="pvalue" value="<%=valueMap%>" />					
  <c:set var="list" value="<%=list%>" />
  	<table width="100%" align="center">
  		<TR>
			  <TH class=listViewPaginationTdS1  align=left colSpan=4>
			   ${typeCname}设置</TH></TR>
		<TR>
		<tr>
			<TH align="right">名&nbsp;称</TH>
			<TH align="left">设置值</TH>
			<TH align="left">默认值</TH>
			<TH align="left">描&nbsp;&nbsp;述</TH>
		</tr>
  		<c:forEach items="${list}" var="fieldList">
  			<tr>
  				<td width="25%" class=dataLabel align="right">${fieldList.cname}：</td>
  				<td width="20%" class=dataField align="left">				
  				<c:set var="values" value="${fieldList.inputValues}" />
  					<c:choose>
  						<c:when test="${fieldList.inputType=='text'}">
							<c:forEach items="${pvalue}" var="map">  										
								<c:if test="${map.key==fieldList.pname}">
				  					<input name="${fieldList.name}" type="${fieldList.inputType}" value="${map.value}" size="${fieldList.inputSize}" ${fieldList.inputValidator} showName="${fieldList.validatorAlertField}" />		  					
				  					
			  					</c:if>		
			  					
  							</c:forEach>
	  					</c:when>
	  					
	  					<c:when test="${fieldList.inputType=='radio'}">
	  						
	  						<c:forEach items="${values}" var="v">
	  							<c:forEach items="${pvalue}" var="map">  		  															
									<c:if test="${map.key==fieldList.pname}">
			  							<input type="radio" name="${fieldList.name}" value="${v.value}" <c:if test="${map.value==v.value}">checked</c:if>  />
			  							${v.name}
			  						</c:if>
			  					</c:forEach>	
	  							
	  						</c:forEach>
	  					</c:when>
	  					
	  					<c:when test="${fieldList.inputType=='select'}">
	  						<c:if test="${fieldList.name eq 'dept_showlevel'}">
	  							<select name="${fieldList.name}">
		  							<c:forEach begin="1" end="<%=dept_maxlevel %>" var="v">
		  								<c:forEach items="${pvalue}" var="map">  		  															
											<c:if test="${map.key==fieldList.pname}">
				  								<option value="${v}" <c:if test="${map.value==v}">selected="selected"</c:if> >${v}</option>
				  							</c:if>
				  						</c:forEach>		
		  							</c:forEach>
		  						</select>
	  						</c:if>
	  						<c:if test="${fieldList.name ne 'dept_showlevel'}">
		  						<select name="${fieldList.name}">
		  							<c:forEach items="${values}" var="v">
		  								<c:forEach items="${pvalue}" var="map">  		  															
											<c:if test="${map.key==fieldList.pname}">
				  								<option value="${v.value}" <c:if test="${map.value==v.value}">selected="selected"</c:if> >${v.name}</option>
				  								
				  							</c:if>
				  						</c:forEach>		
				  						
		  							</c:forEach>
		  						</select>
	  						</c:if>
	  					</c:when>
	  					
  					</c:choose>
  				</td>
  				<td width="20%" align="left" style="word-break: break-all">(${fieldList.defaultValue})</td>
  				<td width="35%" align="left">${fieldList.desc}</td>
  			</tr>
  		</c:forEach>
  	</table>  
  
  
</FORM>  
<c:if test="${typeName=='mail'}"> 
<%
String mailHost=PropertyFile.readValue("firstframe.properties","constant.mail_host")==null?"":PropertyFile.readValue("firstframe.properties","constant.mail_host");
String mailFrom=PropertyFile.readValue("firstframe.properties","constant.mail_from")==null?"":PropertyFile.readValue("firstframe.properties","constant.mail_from");
String mailUsername=PropertyFile.readValue("firstframe.properties","constant.mail_username")==null?"":PropertyFile.readValue("firstframe.properties","constant.mail_username");
String mailPassword=PropertyFile.readValue("firstframe.properties","constant.mail_password")==null?"":PropertyFile.readValue("firstframe.properties","constant.mail_password");

%>
<form method="post" action="mail_test.jsp"">
<c:set var="smtp" value="<%=mailHost%>"/>
<c:set var="sender" value="<%=mailFrom%>"/>
<c:set var="user" value="<%=mailUsername%>"/>
<c:set var="pwd" value="<%=mailPassword%>"/>
	 <table width="100%" align="center">
	  		<TR>
				  <TH class=listViewPaginationTdS1  align=left colSpan=2>
				   邮件测试</TH></TR>
			<TR>
			<tr>
				<Td colspan="2">测试邮件服务器是否工作正常,以下信息来自firstframe.properties文件 </Td>
			</tr>
			<tr>
				<td width="15%">发送邮件服务器:</td>	
				<input type="hidden" name="smtp" value="${smtp}"/>			
				<td width="85%">${smtp}</td>	
			</tr>
			<tr>
				<td width="15%">发送者邮箱:</td>		
				<input type="hidden" name="sender" value="${sender}"/>			
				<td width="85%">${sender}</td>	
			</tr>
			<tr>
				<td width="15%">系统发送者用户名:</td>	
				<input type="hidden" name="user" value="${user}"/>			
				<td width="85%">${user}</td>		
			</tr>
			<tr>
				<td width="15%">发送者密码:</td>	
				<input type="hidden" name="pwd" value="${pwd}"/>				
				<td width="85%">${pwd}</td>	
			</tr>
			
			<tr>
				<td width="15%">&nbsp;</td>
				<td width="85%"> <input type=submit value="测试连接" /></td>
			</tr>
	 </Table>
</form>
</c:if>	
</body>
</html>
